# coding=utf-8
from appium import webdriver
import time
import unittest
from PO.IndexPage import IndexPage
from PO.CityPage import CityList
from Public.log import Logger

log = Logger('TestCity').getlog()
class TestCity(unittest.TestCase):
    def setUp(self):
        capabilities = {
            'platformName': 'Android',
            'platformVersion': '4.4.2',
            'deviceName': '127.0.0.1:62001',
            'appPackage': 'com.guokr.mentor',
            'appActivity': '.ui.activity.MainActivity',
            'unicodeKeyboard': True,
            'resetKeyboard': True,
            'noReset': True
        }
        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", capabilities)
        self.myindex = IndexPage(self.driver)
        self.mycity = CityList(self.driver)

    def tearDown(self):
        self.driver.quit()

    def test02(self):
        """进入城市选择页面"""
        log.info('测试用例开始')
        time.sleep(5)
        self.myindex.city()
        log.info('点击城市')
        self.assertEqual(self.mycity.title(), "选择所在城市")
        log.info('测试用例结束')

    def test03(self):
        """选择城市后返回首页"""
        log.info('测试用例开始')
        self.myindex.city()
        log.info('点击城市')
        time.sleep(1)
        self.mycity.chooseCity()
        log.info('选择城市-上海')
        self.assertEqual(self.myindex.cityShow(), "上海")
        log.info('测试用例结束')

    def test04(self):
        """关闭城市选择窗口，回到首页"""
        self.myindex.city()
        time.sleep(1)
        self.mycity.closePage()
        self.assertTrue(self.myindex.home_page(), '未跳转到首页')


